<?php

declare(strict_types=1);

namespace Service\SupplierService\SupplierMapping;

use Service\BaseService;
use Service\ConsumerService\ConsumerMapping\CommodityMapping;
use Service\ConsumerService\ConsumerMapping\StockInfoMapping;

class BaseMapping extends BaseService
{
    protected $supplierCommodity;
    protected $supplierStock;
    public function __construct()
    {
        $this->supplierCommodity = CommodityMapping::instance();
        $this->supplierStock = StockInfoMapping::instance();
    }


    public function isDateTime($dateTime,$formats=['Y-m-d','Y/m/d','Y-m-d H:i:s','Ymd','Y-m'])
    {
        $unixTime = strtotime($dateTime);
        if (!$unixTime){ //strtotime转换不对，日期格式显然不对。
            return false;
        }
        //校验日期的有效性，只要满足其中一个格式就OK
        foreach ($formats as $format){
            if (date($format,$unixTime)==$dateTime){
                return true;
            }
        }
        return false;
    }

    /**
     * 替换空格换行数据
     * @param string $string
     */
    public static function replaceUnnormalString(string $string)
    {
        return str_replace([PHP_EOL,' '],['',''],$string);
    }
}
